package com.ly.hotel.util;

import java.io.File;
import java.io.FileWriter;

import android.util.Log;

import com.ly.hotel.common.Constants;
import com.ly.hotel.common.MyApplication;

/**
 * @author Administrator 与底部按键配置有关的工具
 */
public class BtnCfgUtil {

	public static void saveBtnCfgToLocalFile(String str) throws Exception {
		File f = new File(Constants.BTN_CFG_FILE_PATH);
		File f_folder = new File(Constants.BTN_CFG_FILE_ROOT);

		System.out.println("通过网络的文件生成本地的按键配置");

		// 检测目录是否存在，没有就新建之
		if (!f_folder.exists()) {
			f_folder.mkdirs();
		}

		// 新建文件
		f.createNewFile();
		FileWriter fw = new FileWriter(Constants.BTN_CFG_FILE_PATH);
		String s = str.replace(",", "\r\n");
		fw.write(s + "\r\n");

		fw.close();
	}

	public static boolean isBtnEnable(String src, String name) {
		boolean enable = false;
		int state = 0;
		String str = "";

		if (src.contains(name)) {
			try {
				str = src.replace(name, "").replace(":", "").replace("\"", "");
				state = Integer.parseInt(str);
			} catch (NumberFormatException n) {
				Log.i("btn", name + "无效状态:" + str);
			}
			if (state == 1)
				enable = true;
		}

//		Log.i("btn", "设置" + name + "状态:" + enable);
		return enable;
	}

	public static void setBtnItemInfo(MyApplication app, String btnName, boolean state) {
		app.setBtnItemInfo(btnName, state);
	}

}
